package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.MrpLinesResultEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.tech.MrpLinesResultRepository;

/**
 * 物料需求计划-物料需求明细信息数据访问对象。
 *
 * @author 吴旭
 */
@Repository("MrpLinesResultRepository")
public class MrpLinesResultRepositoryImpl extends GenericRepositoryImpl<MrpLinesResultEntity, String>
        implements MrpLinesResultRepository {

    private final String namespace = "cn.com.huzo.repository.tech.MrpLinesResultRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public MrpLinesResultRepositoryImpl() {
        super(MrpLinesResultEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpLinesResultEntity> fetchByHeaderId(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Map<String, Object>> fetchForStockOut(Map<String, Object> paramsMap) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForStockOut"), paramsMap);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpLinesResultEntity> fetchByAssortmentType(Long headerId, Short assortmentType, Short sortType) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("AssortmentType", assortmentType);
        criterion.put("SortType", sortType);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByAssortmentType"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpLinesResultEntity> fetchPrintDataByProductColour(
            Long headerId, Long moHeaderId, Long productId, Long productColourId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("MoHeaderId", moHeaderId);
        criterion.put("ProductId", productId);
        criterion.put("ProductColourId", productColourId);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchPrintDataByProductColour"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpLinesResultEntity> fetchPrintDataWithMoFormat(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchPrintDataWithMoFormat"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpLinesResultEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<String> fetchAllSelectedLines(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchAllSelectedLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(MrpLinesResultEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<MrpLinesResultEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteByAssortmentLinesId(String assortmentLinesId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteByAssortmentLinesId"), assortmentLinesId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteByHeaderId(Long headerId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteByHeaderId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateByPriorMrpLines(Long headerId, Long priorMrpHeaderId, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("PriorMrpHeaderId", priorMrpHeaderId);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateByPriorMrpLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateProductQuantity(Map<String, Object> criterion) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateProductQuantity"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateProductQuantityWithDestination(Map<String, Object> criterion) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateProductQuantityWithDestination"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer reCalculate(Map<String, Object> criterion) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "reCalculate"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateByHistoryData(Long headerId, Long historyHeaderId, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("HistoryHeaderId", historyHeaderId);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateByHistoryData"), criterion);
    }

    // <editor-fold defaultstate="collapsed" desc="订单相关用">
    /**
     * {@inheritDoc}
     */
    @Override
    public List<Map<String, Object>> fetchRoundCardQuantityFromMrpByPoHeaderId(Long poHeaderId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchRoundCardQuantityFromMrpByPoHeaderId"), poHeaderId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Map<String, Object>> fetchHangerStickerQuantityFromMrpByPoHeaderId(Long poHeaderId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchHangerStickerQuantityFromMrpByPoHeaderId"), poHeaderId);
    }
    // </editor-fold>
}
